package com.varian.service.exception.handler;

import cn.hutool.core.util.StrUtil;
import com.varian.tool.contant.ResultConstant;
import com.varian.tool.result.IR;
import com.varian.tool.result.R;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.HttpRequestMethodNotSupportedException;

/**
 * @author ben
 * @since 2024/7/10
 */
public class HttpRequestMethodNotSupportedExceptionHandler implements ExceptionHandlerStrategy {
    @Override
    public Class<? extends Exception> getExceptionClass() {
        return HttpRequestMethodNotSupportedException.class;
    }

    @Override
    public IR handle(Exception exception, HttpServletResponse response) {
        HttpRequestMethodNotSupportedException notSupportedException = (HttpRequestMethodNotSupportedException) exception;
        return R.result(ResultConstant.FAIL, ResultConstant.FAIL_CODE,
                StrUtil.format("错误的请求方式: {}", notSupportedException.getMethod()));
    }
}
